//EggReturnCommand.java
package qwq.vincentzyu.Command;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import qwq.vincentzyu.JPTTPlugin;

/**
 * Created by Administrator on 2025/3/13.
 */
public class EggReturnCommand implements CommandExecutor {
    private final JPTTPlugin plugin;

    public EggReturnCommand(JPTTPlugin plugin) {
        this.plugin = plugin;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length != 1 && args.length != 4 && args.length != 6) {
            sender.sendMessage("§c参数错误！可用格式：\n" +
                    "§a/qwq_egg_return <启用>\n" +
                    "§a/qwq_egg_return <启用> <x> <y> <z>\n" +
                    "§a/qwq_egg_return <启用> <x> <y> <z> <pitch> <yaw>");
            return false;
        }

        try{
            boolean arg0_enable = Boolean.parseBoolean(args[0]);
            double[] coords = new double[args.length-1];
            for ( int i=1; i<=args.length-1; i++ ){
                coords[i-1] = Double.parseDouble(args[i]);
            }
            plugin.updateEggConfig(arg0_enable, coords);
            sender.sendMessage("§b鸡蛋传送配置已更新！");
            return true;
        } catch (NumberFormatException e){
            sender.sendMessage("§c坐标参数必须为数字！错误信息：" + e);
            return false;
        } catch (Exception e){
            sender.sendMessage("§c未知错误！错误信息：" + e);
            return false;
        }

    }
}
